package com.example.crm.controller;

import com.example.crm.entity.User;
import com.example.crm.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author lenovo
 */
@Controller
public class LoginController {
    @Resource
    private IUserService userService;

    @RequestMapping(value = "/doLogin")
    public String login(String usrName, String usrPassword, Model model, HttpSession session) {
        User user = userService.login(usrName, usrPassword);
        if(user!=null){
            session.setAttribute("loginUser",user);
            return "redirect:/main";
        }else{
            model.addAttribute("msg","用户名或密码错误，登录失败！");
            return "forward:/login.jsp";
        }
    }

    @RequestMapping("/main")
    public String main(){
        return "main";
    }
}
